﻿using UnityEngine;
using System.Collections;
using Pathfinding.Serialization.JsonFx;

public class LevelDataManager : MonoBehaviour
{
    /// <summary>
    /// 关卡数据保存路径
    /// </summary>
    public static string levelDataPath = Application.streamingAssetsPath + "/LevelData";

    /// <summary>
    /// 加载关卡数据
    /// </summary>
    /// <param name="levelname"></param>
    /// <returns></returns>
    public static LevelBase ReadLevelData(string levelname)
    {
        string levelBaseStr = DataManager.Read(levelDataPath + "/" + levelname + ".txt");
        LevelBase levelBase = JsonReader.Deserialize<LevelBase>(levelBaseStr);
        return levelBase;
    }

    /// <summary>
    /// 保存关卡数据
    /// </summary>
    /// <param name="levelbase"></param>
    /// <param name="levelname"></param>
    public static void WriteLevelData(LevelBase levelbase,string levelname)
    {
        string levelBaseStr = JsonWriter.Serialize(levelbase);
        DataManager.Write(levelBaseStr, levelDataPath, levelname);
    }
}
